package com.totalinlink.sisclient;

import android.graphics.Canvas;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.CanvasTransformer;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

import com.totalinlink.fragment.HomeFragment;
import com.totalinlink.fragment.MenuFragment;

public class MainActivity extends SlidingFragmentActivity {

    private CanvasTransformer mTransformer;
    Fragment mContent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_frame);
        initSlidingMenu();
        // testsasd asd
    }

    /**
     * 设置滑动菜单
     */
    private void initSlidingMenu(){
        mContent = new HomeFragment();
        //设置滑动菜单打开后的视图界面
        setBehindContentView(R.layout.menu_frame);
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit();
        FragmentTransaction mFragementTransaction = getSupportFragmentManager().beginTransaction();

        //菜单的Fragment
        Fragment mFrag = new MenuFragment(this);
        mFragementTransaction.replace(R.id.menu_frame, mFrag);
        mFragementTransaction.commit();

        //设置滑动菜单的属性值，实例化滑动菜单对象
        SlidingMenu sm = getSlidingMenu();
        //设置左滑菜单
        sm.setMode(SlidingMenu.LEFT);
        //设置滑动阴影的宽度
        sm.setShadowWidthRes(R.dimen.shadow_width);
        //设置滑动阴影的图像资源
        sm.setShadowDrawable(R.drawable.shadow);
        //设置滑动菜单视图的宽度
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        //设置滑动时菜单的是否渐变
        sm.setFadeEnabled(true);
        //设置渐入渐出效果的值
        sm.setFadeDegree(0.35f);
        //设置触摸屏幕的模式
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

//        mTransformer = new CanvasTransformer(){
//            @Override
//            public void transformCanvas(Canvas canvas, float percentOpen) {
//                float scale = (float) (percentOpen*0.25 + 0.75);
//                canvas.scale(scale, scale, canvas.getWidth()/2, canvas.getHeight()/2);
//            }
//        };
//        sm.setBehindCanvasTransformer(mTransformer);
    }
    public void switchContent(Fragment fragment) {
        // TODO Auto-generated method stub
        mContent = fragment;
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
        getSlidingMenu().showContent();
    }
}
